import axios from '../utils/http'

const MenuStore = {
    namespaced: true,
    state:()=>({
        menuList: []
    }),//组件使用数据
    mutations:{
        MenuListMutation(state,list){
            //修改state数据
            state.menuList = list
        }
    },
    actions:{
        MenuListAction(context){
            //获取后台数据
            axios.get("/api/menulist?istree=1").then(res=>{
                if(res.code === 403){
                    localStorage.removeItem("login_data")
                    window.location.href = "/#/login"
                }else{
                    if(res.code === 200){
                        context.commit("MenuListMutation",res.list)
                    }    
                }
            })
        }
    }
}

export default MenuStore